<%@page import="com.ignou.mca.beans.ExamBean"%>
<%@page import="java.util.Iterator"%>
<%@page import="java.util.ArrayList"%>
<%@page import="com.ignou.mca.datasource.DatabaseOperations"%>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
	pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<%@page import="com.ignou.mca.beans.UserVO"%><html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" href="theme/style.css"
	media="screen" />
<title>OES - Displaying list of Exams</title>
<script type="text/javascript">
	function deleteExamConfirm(examId)
	{
		var altTxt = "You are trying to delete "+examId+" exam.\n Click 'OK' to continue to delete. \n Click 'Cancel' to cancel the submission. '";
		if (confirm(altTxt))
		{
			window.location.href = 'DeleteExam.jsp?exam='+examId; 
		}
		else
		{
		}
	}
	
	function updateExam(examId)
	{
		window.location.href = 'UpdateExam.jsp?exam='+examId; 
	}

	function viewExam(examId,subjectId)
	{
		newwindow=window.open("./ShowExam.jsp?exam="+examId+"&subject="+subjectId,'Exam','height=400,width=480,resizable=0');
		if (window.focus) {newwindow.focus();}
	}

</script>
</head>
<body>
	<div id="MainWrapper">
		<jsp:include page="header.jsp" /> 
		<jsp:include page="LeftContainer.jsp" />
		<div id="MainContent">
			<center><h2>Exams</h2></center>
		<%
			UserVO uvo = (UserVO) session.getAttribute("UserVO");
			int subjectID = 0;
			if(uvo==null)
			{
				response.sendRedirect("./Login.jsp");
			}
			else
			{
				String sub = request.getParameter("subject");
				DatabaseOperations dbOperations = new DatabaseOperations();
				ArrayList<ExamBean> exams = new ArrayList<ExamBean>();
				subjectID = Integer.parseInt(sub);
				exams = dbOperations.getSubjectRelatedExams(subjectID);
				session.setAttribute("Exam",exams);
				/*if(sub!=null)
				{
					exams = dbOperations.getAllExams();
				}else
				{
					subjectID = Integer.parseInt(sub);
					exams = dbOperations.getSubjectRelatedExams(subjectID);
				}*/
				if(exams.size()<1)
				{
					%>
						<font color="red"> No exams available.</font>
					<%
				}else
				{
					%>
					<table align="center" width="100%" height="100%">	
					<%	
						Iterator<ExamBean> itr = exams.iterator(); 
						while(itr.hasNext()) 
						{
							ExamBean eb = (ExamBean)itr.next();	
						%>
						<tr>
							<td><%= eb.getExamName()%></td>
							<td>  <a href="javascript: viewExam(<%=eb.getExamId() %>,<%=subjectID %>)">View Exam</a></td>
							<td>  <a href="javascript: updateExam(<%=eb.getExamId() %>)">Update Exam</a></td>
							<td>  <a href="javascript: deleteExamConfirm(<%=eb.getExamId() %>);">Delete Exam</a></td>
						</tr>
						<%
						}
						%>
					</table>
					<%
				}
			}
					%>
				<br><br><br>
				Click <a href="Subjects.jsp?">here</a> to go back.<br>
					<!-- Click <a href="AddExam.jsp?subject=<%=subjectID%>">here</a> to add Exam.<br>  -->
		</div>
		<jsp:include page="footer.jsp" />
	</div>
</body>
</html>